package com.zr.java8.pattern.state;

import com.zr.java8.pattern.state.impl.PendingState;

// 订单环境类
public class OrderContext {
    private OrderState currentState;

    // 初始化订单为待支付状态
    public OrderContext() {
        this.currentState = new PendingState();
    }

    // 切换状态
    public void setState(OrderState state) {
        this.currentState = state;
    }

    // 委托支付行为给当前状态
    public void pay() {
        currentState.pay(this);
    }

    // 委托发货行为给当前状态
    public void ship() {
        currentState.ship(this);
    }

    // 委托完成行为给当前状态
    public void complete() {
        currentState.complete(this);
    }

    // 获取当前状态名称
    public String getCurrentStateName() {
        return currentState.getStateName();
    }
}
